package dao

import "go/models"

func Addstudent(student models.Family) error {
	// err := db.Table("student_message").Select("sno", "sname", "ssex", "sage", "sdept", "sedu_sys").Create(&student).Error
	err := db.Table("student_message").Create(&student).Error
	return err
}
func Delstudent(id int) error {
	err := db.Table("student_message").Where("id = ?", id).Update("isdel", true).Error
	return err
}
func Updatestudent(student models.Family) error {
	id := student.Id
	err := db.Table("student_message").Where("id = ?", id).Updates(&student).Error
	return err
}

func Getstudent(studentParam map[string]interface{}) ([]models.Family, int64, error) {
	var studentData []models.Family
	page := studentParam["page"].(int)
	pageSize := studentParam["limit"].(int)
	searchName := studentParam["searchName"].(string)
	var total int64
	err := db.Table("student_message").Where("id like ?", searchName+"%").Order("id ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&studentData).Error
	return studentData, total, err
}
